﻿#region using statements

using Microsoft.Xna.Framework;

using NGen;
using NGen.Managers.GUI;
using NGen.Managers.GameObject;
using NGen.Managers.GameState;

using XNAGameDemo.GUI;
using XNAGameDemo.GameObjects;

#endregion

namespace XNAGameDemo.GameStates
{
	public class GameStatePlay3 : GameState
	{
		private readonly GUIElement m_gui = new GUIElementPlay3State();

		protected override void _Initialize() {
			//load the gui
			GameEngine.GetService<IManagerGUI>().AddElement(m_gui);

			GameObject2D block; //temp variable
			for(var i = 0; i < 4; ++i) {
				//make 2 blocks per loop iteration

				block = new CollidingBlock();
				block.m_position = new Vector2((i + 1) * GameEngine.GameWindow.ClientBounds.Width / 5.0f, GameEngine.GameWindow.ClientBounds.Height / 3.0f);
				//add the block to the game object manager
				GameEngine.GetService<IManagerGameObjects>().AddObject(block);

				block = new CollidingBlock();
				block.m_position.X = (i + 1) * GameEngine.GameWindow.ClientBounds.Width / 5.0f;
				block.m_position.Y = 2 * GameEngine.GameWindow.ClientBounds.Height / 3.0f;
				//add the block to the game object manager
				GameEngine.GetService<IManagerGameObjects>().AddObject(block);
			}

			//add a new mouse ball object to the game obejct manager
			GameEngine.GetService<IManagerGameObjects>().AddObject(new MouseBall());
		}

		protected override void _Cleanup() {
			//clear the gui
			GameEngine.GetService<IManagerGUI>().RemoveElement(m_gui);

			//get rid of all game objects
			GameEngine.GetService<IManagerGameObjects>().DestroyAllGameObjects();
		}

		protected override void _OnFocusLost() {}

		protected override void _OnFocusGained() {}

		protected override void _Update(GameTime p_gameTime) {}

		protected override void _Draw(GameTime p_gameTime) {
			GameEngine.GraphicsDeviceManager.GraphicsDevice.Clear(Color.DarkKhaki);
		}
	}
}